<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

defined('_JEXEC') or die('Restricted access'); 
$listcode = $this->listcode;

JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'description' );

JHTML::_('behavior.modal');
?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if (pressbutton == 'save') {
		
	    <?php if( JRequest::getVar("task") != "edit" ){  ?>
	    if( ! checkNumber(form.coupons_count.value) ){
	        alert("Coupons count is required and must be numberic value");
	        form.coupons_count.focus();
	        return false;
	    }
	    
	    if( ! checkNumber(form.coupon_usage_count.value) ){
	        alert("Coupon usage count is required and must be numberic value");
	        form.coupon_usage_count.focus();
	        return false;
	    }
	    <?php } ?>
	    
	    if( ! checkNumber(form.member_coupon_usage_count.value) ){
	        alert("Member coupon usage count is required and must be numberic value");
	        form.member_coupon_usage_count.focus();
	        return false;
	    }
	    
	    if( ! checkNumber(form.code_length.value) ){
	        alert("Code length is required and must be numberic value");
	        form.code_length.focus();
	        return false;
	    }
	    
	    if( ! checkNumber(form.discount.value) ){
	        alert("Payment discount is required and must be numberic value");
	        form.discount.focus();
	        return false;
	    }
	    
	    if ( form.name.value == "" ) {
			alert("Coupon name is required");
			form.name.focus();
			return;
		}
        
		submitform(pressbutton);		
	}
	else {		
		submitform(pressbutton);
	}
}

// Check numberic value
function checkNumber(value){    
	var numericExpression = /^[0-9]+$/;
	var numericExpression1 = /^[0-9]+\.[0-9]{1,2}$/;
	
	if ( value.match(numericExpression) || value.match(numericExpression1) )
	   return true
	else return false;
}

</script>
	
<form name="adminForm" action="index.php" method="post" enctype="multipart/form-data">
	<table width="100%">
	<tr>
	
		<td width="80%" valign="top" align="left">
		
		    <div style="width:100%;">				
				<fieldset class="adminform">
					<legend><a href="#keys" name="keys"><?php echo JText::_( 'Coupon codes' ); ?></a></legend>
					<table width="100%">
	   <tr>
		    <div style="width:100%;">	
			
    			<table class="adminlist">
    			<thead>
    					<tr>
    						<th width="10" align="left">
    							<?php echo JText::_( 'NUM' ); ?>
    						</th>
    						<th class="title">
    							<?php echo JText::_('Code')?>
    						</th>
    						<th >
    							<?php echo JText::_('Count'); ?>
    						</th>
    						<th >
    							<?php echo JText::_('Used'); ?>
    						</th>
    						<th >
    							<?php echo JText::_('Action'); ?>
    						</th>
    					</tr>
    				</thead>
    				<tbody>
    					<?php
    					$k = 0;    					
    					for ($i=0, $n=count( $listcode ); $i < $n; $i++)
    					{
    						$row = $listcode[$i];
    						$checked 	= JHTML::_('grid.id',   $i, $row->id );
    						JFilterOutput::objectHtmlSafe($row);						
							
    						?>
    						<tr class="<?php echo "row$k"; ?>">
    								<td>
    									<?php echo $i +1; ?>
    								</td>
    								<td>
    									<span class="editlinktip hasTip" title="<?php echo JText::_( 'TITLE' );?>::<?php echo $row->code; ?>">
    										<?php echo $row->code; ?>
    									</span>
    								</td>
    								<td align="center">
    									<?php echo $row->count; ?>
    								</td>								
    								<td align="center">
    									<?php echo $row->used;?>
    								</td>
    								<td align="center">
    								<a href="index.php?option=com_jajobboard&view=jacoupon&layout=edit_code&task=edit_code&code_id=<?php echo $row->id; ?>&tmpl=component&coupon_id=<?php echo $row->coupon_id; ?>" title="Edit"><?php echo JText::_('Edit'); ?></a>
    									  | <a href="index.php?option=com_jajobboard&view=jacoupon&layout=list_code&tmpl=component&task=delete_code&code_id=<?php echo $row->id; ?>&coupon_id=<?php echo $row->coupon_id; ?>" onclick="if ( confirm('Are you really want to delete this coupon code?')) return true; else return false;"><?php echo JText::_("Delete");?></a>
    								</td>
    							</tr>
    						<?php
    						$k = 1 - $k;
    					}
    					?>    					
    				</tbody>
    			</table>
				</fieldset>
			</div>
		</td>
	</tr>
	</table>
	<div class="clr"></div>	
	<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
	<input type="hidden" name="view" value="jacoupon" />	
	<input type="hidden" name="task" value="edit_code" />
	<?php echo JHTML::_( 'form.token' ); ?>	
</form>
<style type="text/css">
	table.admintable td.key{
		width:300px;
	}								
</style>